package cn.wolfcode.wolf2w.cloud.member.service.impl;

import cn.wolfcode.wolf2w.cloud.member.domain.UserInfo;
import cn.wolfcode.wolf2w.cloud.member.reposity.UserInfoRepository;
import cn.wolfcode.wolf2w.cloud.member.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private UserInfoRepository repository;

    @Override
    public void save(UserInfo userInfo) {
        repository.save(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        repository.save(userInfo);
    }

    @Override
    public void delete(String id) {
        repository.deleteById(id);
    }

    @Override
    public UserInfo get(String id) {
        return repository.findById(id).orElse(null);
    }

    @Override
    public List<UserInfo> list() {
        return repository.findAll();
    }

    @Override
    public boolean checkPhone(String phone) {

        UserInfo userInfo = repository.findByPhone(phone);

        return userInfo != null;
    }
}
